package Date;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import net.sf.json.JSONObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;

/**
 * @description:常用日期操作
 * @author: cyy
 **/
public class localDate {
    public static void main(String[] args) {

//        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmsssss");
//        try {
//            Date date = sdf.parse("20210524171150439+0800");
//            String s = sdf.format(date);
//            System.out.println(s);
//            Date date1 = new SimpleDateFormat("yyyyMMddHHmmsssss").parse("20210524171150439+0800");
//            System.out.println("shitutuya:"+date1);
//            System.out.println("flag:"+"2010-01-01".contains("-"));
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
        //当前月的第一天和最后一天
       /* LocalDate firstday = localDate.with(TemporalAdjusters.firstDayOfMonth());
        LocalDate lastDay = localDate.with(TemporalAdjusters.lastDayOfMonth());
        System.out.println("当前月第一天  " + firstday + "    localDate is  " + localDate + " 当前月最后一天 " + lastDay);*/

        //ISO_LOCAL_DATE  BASIC_ISO_DATE区别
        /*System.out.println("ISO_LOCAL_DATE:" + localDate.format(DateTimeFormatter.ISO_LOCAL_DATE));
        System.out.println("BASIC_ISO_DATE:" + localDate.format(DateTimeFormatter.BASIC_ISO_DATE));*/


      /*  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date dd = null;
        try {
            dd = sdf.parse("2021-09-01 17:15:56.0");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String activetimeNew = sdf.format(dd);
        LocalDateTime parse=LocalDateTime.parse(activetimeNew,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println("shitutuya:"+activetimeNew);
        System.out.println("shitutuya:"+parse);
        */


        Date parse = DateUtil.parse("2022-08-24 16:00:00", "yyyy-MM-dd");
        Date newDate = DateUtil.offset(parse, DateField.DAY_OF_MONTH, -30);
        System.out.println("result:" + newDate.toString() + "===" + parse.toString());





    }
}
